/*
ID: simplyz2
LANG: C
TASK: beads
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LEN 351
#define Max(a, b) ((a)<(b) ? (b) : (a))
char str[MAX_LEN*2];
int len;
int left[MAX_LEN*2][2], right[MAX_LEN*2][2];

int
dp()
{
	int i, max = 0;
	left[0][0] = left[0][1] = 0;
	for(i=1; i<=2*len; i++) {
		if(str[i-1] == 'r') {
			left[i][0] = left[i-1][0] + 1;
			left[i][1] = 0;
		} else if(str[i-1] == 'b') {
			left[i][0] = 0;
			left[i][1] = left[i-1][1] + 1;
		} else {
			left[i][0] = left[i-1][0] + 1;
			left[i][1] = left[i-1][1] + 1;
		}
	}
	right[2*len][0] = right[2*len][1] = 0;
	for(i=2*len-1; i>=0; i--) {
		if(str[i] == 'r') {
			right[i][0] = right[i+1][0] + 1;
			right[i][1] = 0;
		} else if(str[i] == 'b') {
			right[i][1] = right[i+1][1] + 1;
			right[i][0] = 0;
		} else {
			right[i][0] = right[i+1][0] + 1;
			right[i][1] = right[i+1][1] + 1;
		}
	}
	for(i=0; i<=2*len; i++) 
		max = Max(max, Max(left[i][0], left[i][1])+Max(right[i][0], right[i][1]));
	max = max > len ? len : max;
	return max;
}

int
main(int argc, char **argv)
{
	char tmp[MAX_LEN];
	freopen("beads.in", "r", stdin);
	freopen("beads.out", "w", stdout);
	while(scanf("%d%s", &len, tmp) != EOF) {
		strcpy(str, tmp);
		strcat(str, tmp);
		printf("%d\n", dp());
	}
	exit(0);
}
